#include "cplayalarm.h"
#include "ui_cplayalarm.h"
#include <QTimer>
#include <QSound>
#include <QFile>
#include <QShowEvent>

CPlayAlarm::CPlayAlarm(const QString &time,
                       const QString &info,
                       int timeOutSeconds,
                       QWidget *parent ) :
    QWidget(parent),
    ui(new Ui::CPlayAlarm)
{
    ui->setupUi(this);
    ui->timeLabel->setText( time );
    ui->infoLabel->setText( info );


    bool bOk = connect( ui->okButoon, SIGNAL( clicked() ), this,
                        SLOT( onOkClicked() ) );
    Q_ASSERT( bOk );

    bOk = connect( ui->rmlButton, SIGNAL( clicked() ), this,
                            SLOT( onrmlClicked() ) );
    Q_ASSERT( bOk );

    music = Phonon::createPlayer(Phonon::MusicCategory,
                                 Phonon::MediaSource(":/files/sounds/Sound/PeonYes2.wav"));

    QTimer::singleShot( timeOutSeconds * 1000, this, SLOT( onShowAlarm()) );
}

CPlayAlarm::~CPlayAlarm()
{
    delete ui;
    if( music )
    {
       delete music;
       music = 0;
    }

}

void CPlayAlarm::showEvent ( QShowEvent * e )
{
    music->setCurrentSource( Phonon::MediaSource( ":/files/sounds/Sound/PeonYes3.wav" ) );
    music->play();
}


void CPlayAlarm::onrmlClicked()
{
    this->hide();
    QTimer::singleShot( 5 * 60 * 1000, this, SLOT( onShowAgain() ) );
}

void CPlayAlarm::onShowAgain()
{
    this->show();
}



void CPlayAlarm::onOkClicked()
{
    this->close();
}

void CPlayAlarm::onShowAlarm()
{
    this->show();
}


